-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature mail scheduler #13
base: main
Are you sure you want to change the base?
Conversation
@@ -0,0 +1 @@ | |||
console.log("Hello, World!"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue: This file does not seem to be useful
|
||
// Main | ||
console.log("🟢 Newsletter Scheduler started... Press CTRL + C to stop."); | ||
cron.schedule('* * * * *', checkAndSendNewsletters); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit-pick: The cron should be defined on the system.
Or better, can you try to use supabase CRON system ? https://supabase.com/blog/supabase-cron
This new feature allows the scheduler to plan and send newsletters as needed, according to a defined periodicity.
For now, the script executed when sending emails is a simple "hello world" in the console to avoid consuming emails in Postmark. However, you can replace it with the actual newsletter-sending script that we have already developed.
The script checks every 10 seconds if there are newsletters to send. If so, it executes the specified script (currently "hello.ts" for testing purposes).
After sending an email, it schedules the next one based on the user's chosen periodicity.
In this example, we plan to send two newsletters at 19:10.
One person wants another newsletter in 5 minutes, and the other in 6 minutes (this demonstrates different periodicity management).
Example in the terminal :
![image](https://private-user-images.githubusercontent.com/122040076/410006041-7d6e25b6-7afb-4b5f-b57f-fc6292f52be7.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkyNjI2MjcsIm5iZiI6MTczOTI2MjMyNywicGF0aCI6Ii8xMjIwNDAwNzYvNDEwMDA2MDQxLTdkNmUyNWI2LTdhZmItNGI1Zi1iNTdmLWZjNjI5MmY1MmJlNy5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjUwMjExJTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI1MDIxMVQwODI1MjdaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT0xZjIzMGE1YzZmMDFmNzk1MjQ3NzQwOTYxN2NjY2RjYjFkOTFhNjQyNjY5NDQ4NGVlMTg2OWI2MWU2Y2M4YzFjJlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCJ9.32aHujrt43q_QnRGhMGebELObggaVtaW4dXetGzbqlE)
Looking at the database after execution :
![image](https://private-user-images.githubusercontent.com/122040076/410006819-5d96f96b-aed2-44f4-9e44-78d0cc582bda.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkyNjI2MjcsIm5iZiI6MTczOTI2MjMyNywicGF0aCI6Ii8xMjIwNDAwNzYvNDEwMDA2ODE5LTVkOTZmOTZiLWFlZDItNDRmNC05ZTQ0LTc4ZDBjYzU4MmJkYS5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjUwMjExJTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI1MDIxMVQwODI1MjdaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT03NDZiNzYwNDA2NmVlZmU0OWVkNjVjMDIyN2I1NzNiNGFkNjc1NGVhMjk3OGM5MWYwYmQ4ZDVkMjFmMTAwODQ1JlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCJ9.-KezcPDrM9Cv4DKgiRxtzd2lBohvGm6eYl_81ZNlKC0)